<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    /* 设置图片的绝对定位，并且距离顶部2px */
    img{
        position: absolute;
        top: 2px;
    }
</style>
<body>
    <!-- 插入一张宽度为100px的图片 -->
    <img src="1.png" alt="" width="100px">
</body>
<script>
    // 获取页面中的img元素
    var pic = document.querySelector("img");

    document.addEventListener("mousemove", function(e) {
        var x = e.pageX;
        var y = e.pageY;
        pic.style.left = x -50 + "px";
        pic.style.top = y -40 + "px";
    });
</script>
</html>